package com.me.modules.sys.controller;

import com.me.modules.common.annotation.SysLog;
import com.me.modules.common.controller.BaseController;
import com.me.modules.common.utils.PageUtils;
import com.me.modules.common.utils.Query;
import com.me.modules.common.utils.Result;
import com.me.modules.sys.entity.ExtendField;
import com.me.modules.sys.service.ExtendFieldService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


/**
 * @author jindouyun
 */
@RestController
//@RequestMapping("/sys/fielddictionary")
@RequestMapping("/sys/extendField")
public class ExtendFieldController extends BaseController {

    @Resource
    private ExtendFieldService extendFieldService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("fielddictionary:list")
    @SysLog("查询自定义扩展表单列表")
    public Result list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<ExtendField> fieldDictionaryList = extendFieldService.queryList(query);
        int total = extendFieldService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(fieldDictionaryList, total, query.getLimit(), query.getPage());

        return Result.ok().put("page", pageUtil);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @SysLog("查询流程扩展表单")
    @RequiresPermissions("fielddictionary:info")
    public Result info(@PathVariable("id") Long id) {
        ExtendField fieldDictionary = extendFieldService.queryObject(id);

        return Result.ok().put("fieldDictionary", fieldDictionary);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @SysLog("保存流程扩展表单")
    @RequiresPermissions("fielddictionary:save")
    public Result save(@RequestBody ExtendField fieldDictionary) {
        extendFieldService.save(fieldDictionary);

        return Result.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("fielddictionary:update")
    @SysLog("修改流程扩展表单")
    public Result update(@RequestBody ExtendField fieldDictionary) {
        extendFieldService.update(fieldDictionary);

        return Result.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("fielddictionary:delete")
    @SysLog("删除流程扩展表单")
    public Result delete(@RequestBody Long[] ids) {
        extendFieldService.deleteBatch(ids);

        return Result.ok();
    }

}
